function Get-CMCliAdvertisement
{
<#
.Synopsis
    Returns client advertisement info.
.Description
    Returns client advertisement info.
.Parameter ComputerName 
    ConfigMgr Client Computer Name
.Parameter Credential 
    Enter Alternate Credentials if required
.Example
    Get-CMCliAdvertisement
.Example
    Get-CMCliAdvertisement MYCMClient
        Returns all instances of the CCM_SoftwareDistribution Class on MYCMClient
.Example
    Get-CMCliAdvertisement MYTESTLABServer get-credential
        Prompts for credentials
.Example
    Get-CMCliAdvertisement MYTESTLABServer $Cred
        uses credentials in $Cred
.Outputs
    Returns all instances from the CCM_SoftwareDistribution Class
.Link
    http://msdn.microsoft.com/en-us/library/cc145304.aspx
.Notes
 NAME:      Get-CMCliAdvertisement
 AUTHOR:    Greg Ramsey
 LASTEDIT:  08/07/2009 00:39:05
#Requires -Version 2.0
#>

[CmdletBinding(
    SupportsShouldProcess=$False,
    SupportsTransactions=$False, 
    ConfirmImpact="None",
    DefaultParameterSetName="")]
param(
[Parameter(Position=0)]
$ComputerName="." ,

[Parameter(Position=1)]
$Credential
)

Begin
{
}#Begin

Process
{
    if ($Credential -eq $null)
    {
       get-wmiobject -class CCM_SoftwareDistribution -namespace "root/ccm/Policy/Machine/ActualConfig" -computername $ComputerName
    }
    else 
    {
	   get-wmiobject -class CCM_SoftwareDistribution -namespace "root/ccm/Policy/Machine/ActualConfig" -computername $ComputerName -Credential $Credential
    }
}#Process

End
{
}#End
}

function Get-CMCliInvStatus
{
<#
.Synopsis
    Returns client inventory status info.
.Description
    Returns client inventory info.
.Parameter ComputerName 
    ConfigMgr Client Computer Name
.Parameter Credential 
    Enter Alternate Credentials if required
.Example
    Get-CMCliInvStatus
.Example
    Get-CMCliInvStatus MYCMClient
        Returns all inventory action information on MYCMClient
.Example
    Get-CMCliAdvertisement MYCMClinet get-credential
        Prompts for credentials
.Example
    Get-CMCliAdvertisement MYCMClient $Cred
        uses credentials in $Cred
.Outputs
    Returns all instances from the CCM_SoftwareDistribution Class
.Link
    http://msdn.microsoft.com/en-us/library/cc143565.aspx
.Notes
 NAME:      Get-CMCliInvStatus
 AUTHOR:    Greg Ramsey
 LASTEDIT:  3/31/2010 00:39:05
#Requires -Version 2.0
#>

[CmdletBinding(
    SupportsShouldProcess=$False,
    SupportsTransactions=$False, 
    ConfirmImpact="None",
    DefaultParameterSetName="")]
param(
[Parameter(Position=0)]
$ComputerName="." ,

[Parameter(Position=1)]
$Credential
)

Begin
{
}#Begin

Process
{
    if ($Credential -eq $null)
    {
       $ColItems = get-wmiobject -class InventoryActionStatus -namespace "root\ccm\invagt" -computername $ComputerName
    }
    else 
    {
	   $ColItems = get-wmiobject -class InventoryActionStatus -namespace "root\ccm\invagt" -computername $ComputerName -Credential $Credential
    }

    $colObjs = @()
	$colItems | foreach {
        $obj = New-Object PSObject -Property @{
        ComputerName = $Null
        InvType = $Null
        ReportDate_GMT = $Null
        }
        $obj.ComputerName = $ComputerName
		switch ($_.InventoryActionID)
		{
			"{00000000-0000-0000-0000-000000000001}" `
				{$obj.InvType = "Hardware Inventory"}
			"{00000000-0000-0000-0000-000000000002}" `
				{$obj.InvType = "Software Inventory"}
			"{00000000-0000-0000-0000-000000000003}" `
				{$obj.InvType = "Discovery Data Record"}
			"{00000000-0000-0000-0000-000000000021}" `
				{$obj.InvType = "Machine Policy Refresh"}
			"{00000000-0000-0000-0000-000000000010}" `
				{$obj.InvType = "File Collection"}
			"{00000000-0000-0000-0000-000000000022}" `
				{$obj.InvType = "SW Metering Usage Report Cycle"}
			"{00000000-0000-0000-0000-000000000032}" `
				{$obj.InvType = "MSI Product Source Update Cycle"}
		}
		$obj.ReportDate_GMT = $_.ConvertToDateTime($_.LastReportDate)
       # write-host $obj
     $colObjs = $colObjs + $obj   
     #$obj = $nothing
   # $colobjs
    }
    $colObjs
}#Process

End
{
}#End
}



function Invoke-CMCliSched
{
<#
.Synopsis
    Executes Client Schedule Methods.
.Description
    Executes Client Schedule Methods.
.Parameter ComputerName 
    ConfigMgr Client Computer Name
.Parameter Credential 
    Enter Alternate Credentials if required
.Example
    Invoke-CMCliSched
.Example
    Invoke-CMCliScheds MYCMClient HWINV
        Triggers the Hardware Inventory client agent cycle, to initiate HW inventory.
.Example
    Invoke-CMCliScheds MYCMClient HWINV get-credential
        Triggers the Hardware Inventory client agent cycle, to initiate HW inventory, and prompts for credentials.
.Example
    Invoke-CMCliScheds MYCMClient HWINV $cred
        Triggers the Hardware Inventory client agent cycle, to initiate HW inventory, using credentials stored in $cred
.Outputs
    Returns success or failure code.
.Link
    http://msdn.microsoft.com/en-us/library/cc146352.aspx
.Notes
 NAME:      Invoke-CMCliSched
 AUTHOR:    Greg Ramsey
 LASTEDIT:  3/31/2010 00:39:05
#Requires -Version 2.0
#>

[CmdletBinding(
    SupportsShouldProcess=$False,
    SupportsTransactions=$False, 
    ConfirmImpact="None",
    DefaultParameterSetName="")]
param(
[Parameter(Mandatory=$True,HelpMessage="Enter Remote Computer Name",Position=0)]
$ComputerName="." ,
[Parameter(Mandatory=$True,HelpMessage="Enter HWInv, SWInv, DDR, MachPol, FileCol, SWM, or MSIProd",Position=1)]
$Action,
[Parameter(Position=2)]
$Credential
)

Begin
{
}#Begin

Process
{
    switch ($Action)
    {
    	"HWInv" {$SchedID = "{00000000-0000-0000-0000-000000000001}"}
    	"SWInv" {$SchedID = "{00000000-0000-0000-0000-000000000002}"} 
    	"DDR"	{$schedID = "{00000000-0000-0000-0000-000000000003}"}
    	"MachPol" {$SchedID = "{00000000-0000-0000-0000-000000000021}"}
    	"FileCol" {$SchedID = "{00000000-0000-0000-0000-000000000010}"}
    	"SWM"	{$SchedID = "{00000000-0000-0000-0000-000000000022}"}
    	"MSIProd" {$SchedID = "{00000000-0000-0000-0000-000000000032}"}
    }
    
    if ($Credential -eq $null)
    {
      # $ColItems = get-wmiobject -class InventoryActionStatus -namespace "root\ccm\invagt" -computername $ComputerName

      if ($ComputerName -eq ".")
      {
        $ComputerName = $env:computername
      }
        write-host "\\$ComputerName\root\ccm:SMS_Client"
        $path = "\\$ComputerName\root\ccm:SMS_Client"
       $SMSCli = [wmiclass] $path
       $SMSCli.TriggerSchedule($SchedID)
    }
    else 
    {
        write-host "No support for the -Credential argument currently. :( "
    }
    



}#Process

End
{
}#End
}

function Invoke-CMRediscoverSite
{
<#
.Synopsis
    Executes Client Auto Rediscovery for Site Assignment.
.Description
    Executes Client Auto Rediscovery for Site Assignment.
.Parameter ComputerName 
    ConfigMgr Client Computer Name
.Parameter Credential 
    Enter Alternate Credentials if required
.Example
    Invoke-CMRediscoverSite
.Example
    Invoke-CMRediscoverSite
        Executes Client Auto Rediscovery for Site Assignment.
.Example
    Invoke-CMRediscoverSite MYCMClientget -credential
        Executes Client Auto Rediscovery for Site Assignment, and prompts for credentials.
.Example
    Invoke-CMCliScheds MYCMClient $cred
        Executes Client Auto Rediscovery for Site Assignment, using credentials stored in $cred
.Outputs
    Returns success or failure code.
.Link
    http://msdn.microsoft.com/en-us/library/cc146352.aspx
.Notes
 NAME:      Invoke-CMRediscoverSite
 AUTHOR:    Greg Ramsey
 LASTEDIT:  3/31/2010 00:39:05
#Requires -Version 2.0
#>

[CmdletBinding(
    SupportsShouldProcess=$False,
    SupportsTransactions=$False, 
    ConfirmImpact="None",
    DefaultParameterSetName="")]
param(
[Parameter(Position=0)]
$ComputerName="." ,
[Parameter(Position=1)]
$Credential
)

Begin
{
}#Begin

Process
{
    if ($Credential -eq $null)
    {
       $Obj = get-wmiobject -class SMS_Client -namespace "root/ccm" -computername $ComputerName
       $Obj.EnableAutoAssignment = $true
       $Obj.Put() | out-null
       write-host "Stopping CCMExec on $ComputerName"
       get-wmiobject win32_service -computername $ComputerName | where-object {$_.Name-eq "ccmexec"} | foreach {$_.StopService()} | out-null
	   start-sleep 5
       write-host "Starting CCMExec on $ComputerName"
	   get-wmiobject win32_service -computername $ComputerName | where-object {$_.Name-eq "ccmexec"} | foreach {$_.StartService()} | out-null
    }
    else 
    {
	   $Obj = get-wmiobject -class SMS_Client -namespace "root/ccm" -computername $ComputerName -Credential $Credential
       $Obj.EnableAutoAssignment = $true
       $Obj.Put() | out-null
       write-host "Stopping CCMExec on $ComputerName"
       get-wmiobject win32_service -computername $ComputerName  -Credential $Credential | where-object {$_.Name-eq "ccmexec"} | foreach {$_.StopService()} | out-null
	   start-sleep 5
       write-host "Starting CCMExec on $ComputerName"
	   get-wmiobject win32_service -computername $ComputerName  -Credential $Credential | where-object {$_.Name-eq "ccmexec"} | foreach {$_.StartService()} | out-null      
    }
    

}#Process

End
{
}#End
}

